package com.inossem.warehousestorage_inossem.utils;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.adapter.OverviewAdapter;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStoragePickingBatchListBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStoragePickingConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStoragePickingOverviewBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageReturnConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageReturnOverviewBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageSaleConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageSaleOverviewBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leij on 2017/7/25.
 */

public class OutStorageUtils {

    private static final String IS_FOCUS_TRUE = "1";  //允许修改过账日期

    private static final String IS_FOCUS_FALSE = "0";//不允许修改过账日期

    //获取领料出库信息
    public static OutStoragePickingOverviewBean getOutStoragePickingOverviewBean(Context context) {
        String json = SPUtils.getPickingOutStorageInformation(context);
        Gson gson = new Gson();
        return gson.fromJson(json, OutStoragePickingOverviewBean.class);
    }

    //保存领料出库信息
    public static void saveOutStoragePickingOverviewBean(Context context, OutStoragePickingOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.savePickingOutStorageInformation(context, gson.toJson(bean, OutStoragePickingOverviewBean.class));
    }

    //获取销售出库信息
    public static OutStorageSaleOverviewBean getOutStorageSaleOverviewBean(Context context) {
        String json = SPUtils.getSaleOutStorageInformation(context);
        Gson gson = new Gson();
        return gson.fromJson(json, OutStorageSaleOverviewBean.class);
    }

    //获取销售出库信息
    public static void saveOutStorageSaleOverviewBean(Context context, OutStorageSaleOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.saveSaleOutStorageInformation(context, gson.toJson(bean, OutStorageSaleOverviewBean.class));
    }

    //获取领料退库信息
    public static OutStorageReturnOverviewBean getOutStorageReturnOverviewBean(Context context) {
        String json = SPUtils.getReturnOutStorageInformation(context);
        Gson gson = new Gson();
        return gson.fromJson(json, OutStorageReturnOverviewBean.class);
    }

    //保存领料退库信息
    public static void saveOutStorageReturnOverviewBean(Context context, OutStorageReturnOverviewBean bean) {
        Gson gson = new Gson();
        SPUtils.saveReturnOutStorageInformation(context, gson.toJson(bean, OutStorageReturnOverviewBean.class));
    }

    //通过序号获取领料出库详情
    public static OutStoragePickingOverviewBean.DataBean.MaterielListBean getPickingOutStorageDetailBySerial(Context context, String serial) {
        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> MaterielList = getOutStoragePickingOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < MaterielList.size(); i++) {
            OutStoragePickingOverviewBean.DataBean.MaterielListBean bean = MaterielList.get(i);
            if (bean.getSerial().equals(serial)) {
                return bean;
            }
        }
        return null;
    }

    //通过序号获取销售出库详情
    public static OutStorageSaleOverviewBean.DataBean.MaterielListBean getSaleOutStorageDetailBySerial(Context context, String serial) {
        List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> MaterielList = getOutStorageSaleOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < MaterielList.size(); i++) {
            OutStorageSaleOverviewBean.DataBean.MaterielListBean bean = MaterielList.get(i);
            if (bean.getSerial().equals(serial)) {
                return bean;
            }
        }
        return null;
    }

    //通过序号获取采购退货详情
    public static OutStorageReturnOverviewBean.DataBean.MaterielListBean getReturnOutStorageDetailBySerial(Context context, String serial) {
        List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> MaterielList = getOutStorageReturnOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < MaterielList.size(); i++) {
            OutStorageReturnOverviewBean.DataBean.MaterielListBean bean = MaterielList.get(i);
            if (bean.getSerial().equals(serial)) {
                return bean;
            }
        }
        return null;
    }

    //更新领料出库详情
    public static void updatePickingOutStorageDetail(Context context, OutStoragePickingOverviewBean.DataBean.MaterielListBean materielItem) {
        OutStoragePickingOverviewBean bean = getOutStoragePickingOverviewBean(context);
        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> pickingOutStorageList = bean.getData().getMaterielList();
        for (int i = 0; i < pickingOutStorageList.size(); i++) {
            OutStoragePickingOverviewBean.DataBean.MaterielListBean pickingOutStorageItem = pickingOutStorageList.get(i);
            if (materielItem.getSerial().equals(pickingOutStorageItem.getSerial())) {
                pickingOutStorageList.remove(pickingOutStorageItem);
                break;
            }
        }
        pickingOutStorageList.add(0, materielItem);
        bean.getData().setMaterielList(pickingOutStorageList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStoragePickingOverviewBean.class);
        SPUtils.savePickingOutStorageInformation(context, json);
    }

    //更新销售出库详情
    public static void updateSaleOutStorageDetail(Context context, OutStorageSaleOverviewBean.DataBean.MaterielListBean materielItem) {
        OutStorageSaleOverviewBean bean = getOutStorageSaleOverviewBean(context);
        List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> saleOutStorageList = bean.getData().getMaterielList();
        for (int i = 0; i < saleOutStorageList.size(); i++) {
            OutStorageSaleOverviewBean.DataBean.MaterielListBean saleOutStorageItem = saleOutStorageList.get(i);
            if (materielItem.getSerial().equals(saleOutStorageItem.getSerial())) {
                saleOutStorageList.remove(saleOutStorageItem);
                break;
            }
        }
        saleOutStorageList.add(0, materielItem);
        bean.getData().setMaterielList(saleOutStorageList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStorageSaleOverviewBean.class);
        SPUtils.saveSaleOutStorageInformation(context, json);
    }

    //更新采购退货详情
    public static void updateReturnOutStorageDetail(Context context, OutStorageReturnOverviewBean.DataBean.MaterielListBean materielItem) {
        OutStorageReturnOverviewBean bean = getOutStorageReturnOverviewBean(context);
        List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> returnOutStorageList = bean.getData().getMaterielList();
        for (int i = 0; i < returnOutStorageList.size(); i++) {
            OutStorageReturnOverviewBean.DataBean.MaterielListBean saleOutStorageItem = returnOutStorageList.get(i);
            if (materielItem.getSerial().equals(saleOutStorageItem.getSerial())) {
                returnOutStorageList.remove(saleOutStorageItem);
                break;
            }
        }
        returnOutStorageList.add(0, materielItem);
        bean.getData().setMaterielList(returnOutStorageList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStorageReturnOverviewBean.class);
        SPUtils.saveReturnOutStorageInformation(context, json);
    }

    //过滤领料出库货品列表信息
    public static List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> getPickingOutStorageList(Context context, String materiel) {
        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> pickingOutStorageList = new ArrayList<>();
        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> allPickingOutStorageList = getOutStoragePickingOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < allPickingOutStorageList.size(); i++) {
            OutStoragePickingOverviewBean.DataBean.MaterielListBean item = allPickingOutStorageList.get(i);
            if (item.getMaterielCode().contains(materiel) || item.getMaterielDescription().contains(materiel)) {
                pickingOutStorageList.add(item);
                continue;
            }
        }
        return pickingOutStorageList;
    }

    //过滤销售出库货品列表信息
    public static List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> getSaleOutStorageList(Context context, String materiel) {
        List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> saleOutStorageList = new ArrayList<>();
        List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> allSaleOutStorageList = getOutStorageSaleOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < allSaleOutStorageList.size(); i++) {
            OutStorageSaleOverviewBean.DataBean.MaterielListBean item = allSaleOutStorageList.get(i);
            if (item.getMaterielCode().contains(materiel) || item.getMaterielDescription().contains(materiel)) {
                saleOutStorageList.add(item);
                continue;
            }
        }
        return saleOutStorageList;
    }

    //过滤采购退货货品列表信息
    public static List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> getReturnOutStorageList(Context context, String materiel) {
        List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> returnOutStorageList = new ArrayList<>();
        List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> allReturnOutStorageList = getOutStorageReturnOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < allReturnOutStorageList.size(); i++) {
            OutStorageReturnOverviewBean.DataBean.MaterielListBean item = allReturnOutStorageList.get(i);
            if (item.getMaterielCode().contains(materiel) || item.getMaterielDescription().contains(materiel)) {
                returnOutStorageList.add(item);
                continue;
            }
        }
        return returnOutStorageList;
    }


//    public static boolean checkPickingOutStorageNumber(Context context) {
//        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> materielList = getOutStoragePickingOverviewBean(context).getData().getMaterielList();
//        for (int i = 0; i < materielList.size(); i++) {
//            OutStoragePickingOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
//            if (!TextUtils.isEmpty(materielItem.getActualSendNumber()) && Float.parseFloat(materielItem.getActualSendNumber()) > 0) {
//                return true;
//            }
//        }
//        return false;
//    }

    //检查领料出库列表是否至少填写一项
    public static int getPickingOutStorageNumber(Context context) {
        int result = 0;
        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> materielList = getOutStoragePickingOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < materielList.size(); i++) {
            OutStoragePickingOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getActualSendNumber()) && Float.parseFloat(materielItem.getActualSendNumber()) > 0) {
                result = result + 1;
            }
        }
        return result;
    }

    //检查销售出库列表是否至少填写一项
    public static int getSaleOutStorageNumber(Context context) {
        int result = 0;
        List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> materielList = getOutStorageSaleOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < materielList.size(); i++) {
            OutStorageSaleOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getActualSendNumber()) && Float.parseFloat(materielItem.getActualSendNumber()) > 0) {
                result = result + 1;
            }
        }
        return result;
    }

    //检查领料退库列表是否至少填写一项
    public static int getReturnOutStorageNumber(Context context) {
        int result = 0;
        List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> materielList = getOutStorageReturnOverviewBean(context).getData().getMaterielList();
        for (int i = 0; i < materielList.size(); i++) {
            OutStorageReturnOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getActualSendNumber()) && Float.parseFloat(materielItem.getActualSendNumber()) > 0) {
                result = result + 1;
            }
        }
        return result;
    }

    //删除领料出库验收人
    public static void deletePickingOperator(Context context, String id) {
        OutStoragePickingOverviewBean bean = getOutStoragePickingOverviewBean(context);
        List<OutStoragePickingOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            OutStoragePickingOverviewBean.DataBean.OperatorListBean operatorItem = operatorList.get(i);
            if (operatorItem.getId().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getData().setOperatorList(operatorList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStoragePickingOverviewBean.class);
        SPUtils.savePickingOutStorageInformation(context, json);
    }

    //删除销售出库验收人
    public static void deleteSaleOperator(Context context, String id) {
        OutStorageSaleOverviewBean bean = getOutStorageSaleOverviewBean(context);
        List<OutStorageSaleOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            OutStorageSaleOverviewBean.DataBean.OperatorListBean operatorItem = operatorList.get(i);
            if (operatorItem.getId().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getData().setOperatorList(operatorList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStorageSaleOverviewBean.class);
        SPUtils.saveSaleOutStorageInformation(context, json);
    }

    //删除采购退货验收人
    public static void deleteReturnOperator(Context context, String id) {
        OutStorageReturnOverviewBean bean = getOutStorageReturnOverviewBean(context);
        List<OutStorageReturnOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            OutStorageReturnOverviewBean.DataBean.OperatorListBean operatorItem = operatorList.get(i);
            if (operatorItem.getId().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getData().setOperatorList(operatorList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStorageReturnOverviewBean.class);
        SPUtils.saveReturnOutStorageInformation(context, json);
    }

    //添加领料出库验收人
    public static void addPickingOperator(Context context, OutStoragePickingOverviewBean.DataBean.OperatorListBean receiveItem) {
        OutStoragePickingOverviewBean bean = getOutStoragePickingOverviewBean(context);
        List<OutStoragePickingOverviewBean.DataBean.OperatorListBean> receiverList = bean.getData().getOperatorList() == null ? new ArrayList<>() : bean.getData().getOperatorList();
        receiverList.add(0, receiveItem);
        bean.getData().setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStoragePickingOverviewBean.class);
        SPUtils.savePickingOutStorageInformation(context, json);
    }

    //添加销售出库验收人
    public static void addSaleOperator(Context context, OutStorageSaleOverviewBean.DataBean.OperatorListBean receiveItem) {
        OutStorageSaleOverviewBean bean = getOutStorageSaleOverviewBean(context);
        List<OutStorageSaleOverviewBean.DataBean.OperatorListBean> receiverList = bean.getData().getOperatorList() == null ? new ArrayList<>() : bean.getData().getOperatorList();
        receiverList.add(0, receiveItem);
        bean.getData().setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStorageSaleOverviewBean.class);
        SPUtils.saveSaleOutStorageInformation(context, json);
    }

    //添加采购退货验收人
    public static void addReturnOperator(Context context, OutStorageReturnOverviewBean.DataBean.OperatorListBean receiveItem) {
        OutStorageReturnOverviewBean bean = getOutStorageReturnOverviewBean(context);
        List<OutStorageReturnOverviewBean.DataBean.OperatorListBean> receiverList = bean.getData().getOperatorList() == null ? new ArrayList<>() : bean.getData().getOperatorList();
        receiverList.add(0, receiveItem);
        bean.getData().setOperatorList(receiverList);
        Gson gson = new Gson();
        String json = gson.toJson(bean, OutStorageReturnOverviewBean.class);
        SPUtils.saveReturnOutStorageInformation(context, json);
    }

    //是否有领料出库操作人员
    public static boolean hasPickingOperator(Context context) {
        List<OutStoragePickingOverviewBean.DataBean.OperatorListBean> operatorList = getOutStoragePickingOverviewBean(context).getData().getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //是否有销售出库操作人员
    public static boolean hasSaleOperator(Context context) {
        List<OutStorageSaleOverviewBean.DataBean.OperatorListBean> operatorList = getOutStorageSaleOverviewBean(context).getData().getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //是否有采购退货操作人员
    public static boolean hasReturnOperator(Context context) {
        List<OutStorageReturnOverviewBean.DataBean.OperatorListBean> operatorList = getOutStorageReturnOverviewBean(context).getData().getOperatorList();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //拼领料出库对象
    public static OutStoragePickingConfirmRequestBean getOutStoragePickingConfirmRequestBean(Context context, String voucherDate, String postDate, boolean isFocus) {
        OutStoragePickingConfirmRequestBean result = new OutStoragePickingConfirmRequestBean();
        OutStoragePickingOverviewBean bean = getOutStoragePickingOverviewBean(context);
        result.setPickingNumber(bean.getData().getPickingNumber());
        result.setOutStorageNumber(bean.getData().getOutStorageNumber());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<OutStoragePickingConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<OutStoragePickingOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            OutStoragePickingConfirmRequestBean.OperatorListBean operator = new OutStoragePickingConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<OutStoragePickingConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> materielList = bean.getData().getMaterielList();
        for (int i = 0; i < materielList.size(); i++) {
            OutStoragePickingConfirmRequestBean.MaterielListBean resultMateriel = new OutStoragePickingConfirmRequestBean.MaterielListBean();
            OutStoragePickingOverviewBean.DataBean.MaterielListBean materiel = materielList.get(i);
            resultMateriel.setSerial(materiel.getSerial());
            resultMateriel.setMaterielCode(materiel.getMaterielCode());
            resultMateriel.setOutStorageNumber(materiel.getActualSendNumber());
            List<OutStoragePickingConfirmRequestBean.MaterielListBean.PositionListBean> resultPositionList = new ArrayList<>();
            List<OutStoragePickingBatchListBean.DataBean.BatchListBean> positionList = materiel.getBatchList() == null ? new ArrayList<>() : materiel.getBatchList();
            for (int j = 0; j < positionList.size(); j++) {
                OutStoragePickingConfirmRequestBean.MaterielListBean.PositionListBean resultPosition = new OutStoragePickingConfirmRequestBean.MaterielListBean.PositionListBean();
                OutStoragePickingBatchListBean.DataBean.BatchListBean position = positionList.get(j);
                resultPosition.setBatch(position.getBatch());
                resultPosition.setNumber(position.getOutStorageNumber());
                resultPosition.setPosition(position.getPosition());
                resultPositionList.add(resultPosition);
            }
            resultMateriel.setPositionList(resultPositionList);
            if (!TextUtils.isEmpty(resultMateriel.getOutStorageNumber())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    //拼销售出库对象
    public static OutStorageSaleConfirmRequestBean getOutStorageSaleConfirmRequestBean(Context context, String voucherDate, String postDate, Boolean isFocus) {
        OutStorageSaleConfirmRequestBean result = new OutStorageSaleConfirmRequestBean();
        OutStorageSaleOverviewBean bean = getOutStorageSaleOverviewBean(context);
        result.setSaleNumber(bean.getData().getSaleNumber());
        result.setOutStorageNumber(bean.getData().getOutStorageNumber());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<OutStorageSaleConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<OutStorageSaleOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            OutStorageSaleConfirmRequestBean.OperatorListBean operator = new OutStorageSaleConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<OutStorageSaleConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> materielList = bean.getData().getMaterielList();
        for (int i = 0; i < materielList.size(); i++) {
            OutStorageSaleConfirmRequestBean.MaterielListBean resultMateriel = new OutStorageSaleConfirmRequestBean.MaterielListBean();
            OutStorageSaleOverviewBean.DataBean.MaterielListBean materiel = materielList.get(i);
            resultMateriel.setSerial(materiel.getSerial());
            resultMateriel.setOutStorageNumber(materiel.getActualSendNumber());
            resultMateriel.setMaterielCode(materiel.getMaterielCode());
            List<OutStorageSaleConfirmRequestBean.MaterielListBean.PositionListBean> resultPositionList = new ArrayList<>();
            List<OutStoragePickingBatchListBean.DataBean.BatchListBean> positionList = materiel.getBatchList() == null ? new ArrayList<>() : materiel.getBatchList();
            for (int j = 0; j < positionList.size(); j++) {
                OutStorageSaleConfirmRequestBean.MaterielListBean.PositionListBean resultPosition = new OutStorageSaleConfirmRequestBean.MaterielListBean.PositionListBean();
                OutStoragePickingBatchListBean.DataBean.BatchListBean position = positionList.get(j);
                resultPosition.setBatch(position.getBatch());
                resultPosition.setNumber(position.getOutStorageNumber());
                resultPosition.setPosition(position.getPosition());
                resultPositionList.add(resultPosition);
            }
            resultMateriel.setPositionList(resultPositionList);
            if (!TextUtils.isEmpty(resultMateriel.getOutStorageNumber())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    //拼采购退货对象
    public static OutStorageReturnConfirmRequestBean getOutStorageReturnConfirmRequestBean(Context context, String voucherDate, String postDate, boolean isFocus) {
        OutStorageReturnConfirmRequestBean result = new OutStorageReturnConfirmRequestBean();
        OutStorageReturnOverviewBean bean = getOutStorageReturnOverviewBean(context);
        result.setPurchaseNumber(bean.getData().getPurchaseNumber());
        result.setOutStorageNumber(bean.getData().getOutStorageNumber());
        result.setVoucherDate(voucherDate);
        result.setPostDate(postDate);
        result.setIsFocus(isFocus ? IS_FOCUS_TRUE : IS_FOCUS_FALSE);
        //操作人
        List<OutStorageReturnConfirmRequestBean.OperatorListBean> resultOperatorList = new ArrayList<>();
        List<OutStorageReturnOverviewBean.DataBean.OperatorListBean> operatorList = bean.getData().getOperatorList();
        for (int i = 0; i < operatorList.size(); i++) {
            OutStorageReturnConfirmRequestBean.OperatorListBean operator = new OutStorageReturnConfirmRequestBean.OperatorListBean();
            operator.setRoleCode(operatorList.get(i).getRoleCode());
            operator.setId(operatorList.get(i).getId());
            resultOperatorList.add(operator);
        }
        result.setOperatorList(resultOperatorList);
        //物料
        List<OutStorageReturnConfirmRequestBean.MaterielListBean> resultMaterielList = new ArrayList<>();
        List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> materielList = bean.getData().getMaterielList();
        for (int i = 0; i < materielList.size(); i++) {
            OutStorageReturnConfirmRequestBean.MaterielListBean resultMateriel = new OutStorageReturnConfirmRequestBean.MaterielListBean();
            OutStorageReturnOverviewBean.DataBean.MaterielListBean materiel = materielList.get(i);
            resultMateriel.setSerial(materiel.getSerial());
            resultMateriel.setOutStorageNumber(materiel.getActualSendNumber());
            resultMateriel.setMaterielCode(materiel.getMaterielCode());
            List<OutStorageReturnConfirmRequestBean.MaterielListBean.PositionListBean> resultPositionList = new ArrayList<>();
            List<OutStoragePickingBatchListBean.DataBean.BatchListBean> positionList = materiel.getBatchList() == null ? new ArrayList<>() : materiel.getBatchList();
            for (int j = 0; j < positionList.size(); j++) {
                OutStorageReturnConfirmRequestBean.MaterielListBean.PositionListBean resultPosition = new OutStorageReturnConfirmRequestBean.MaterielListBean.PositionListBean();
                OutStoragePickingBatchListBean.DataBean.BatchListBean position = positionList.get(j);
                resultPosition.setBatch(position.getBatch());
                resultPosition.setNumber(position.getOutStorageNumber());
                resultPosition.setPosition(position.getPosition());
                resultPositionList.add(resultPosition);
            }
            resultMateriel.setPositionList(resultPositionList);
            if (!TextUtils.isEmpty(resultMateriel.getOutStorageNumber())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setMaterielList(resultMaterielList);
        return result;
    }

    public static void updatePickingOutStorageNumber(Context context, String outStorageNumber) {
        OutStoragePickingOverviewBean bean = getOutStoragePickingOverviewBean(context);
        bean.getData().setOutStorageNumber(outStorageNumber);
        saveOutStoragePickingOverviewBean(context, bean);
    }

    public static void updateReturnOutStorageNumber(Context context, String outStorageNumber) {
        OutStorageReturnOverviewBean bean = getOutStorageReturnOverviewBean(context);
        bean.getData().setOutStorageNumber(outStorageNumber);
        saveOutStorageReturnOverviewBean(context, bean);
    }

    public static void updateSaleOutStorageNumber(Context context, String outStorageNumber) {
        OutStorageSaleOverviewBean bean = getOutStorageSaleOverviewBean(context);
        bean.getData().setOutStorageNumber(outStorageNumber);
        saveOutStorageSaleOverviewBean(context, bean);
    }

    //获取领料出库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithPickingOutStorageList(List<OutStoragePickingOverviewBean.DataBean.MaterielListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            OutStoragePickingOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getActualSendNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getActualSendNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取销售出库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithSaleOutStorageList(List<OutStorageSaleOverviewBean.DataBean.MaterielListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            OutStorageSaleOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getActualSendNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getActualSendNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取采购退货行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithReturnOutStorageList(List<OutStorageReturnOverviewBean.DataBean.MaterielListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            OutStorageReturnOverviewBean.DataBean.MaterielListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getActualSendNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMaterielDescription());
                overItem.setNumber(materielItem.getActualSendNumber() + materielItem.getUnit());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

}
